﻿using Abp.Application.Services.Dto;
using Abp.Authorization;
using shenghua.Authorization;
using shenghua.Basics.MemberFormItems;
using shenghua.Basics.MemberFormItemSetting.Dto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace shenghua.Basics.MemberFormItemSetting
{
    [AbpAuthorize(PermissionNames.MemberFormItemManagement)]
    public class MemberFormItemSettingAppService: shenghuaAppServiceBase, IMemberFormItemSettingAppService
    {
        private readonly MemberFormItemManager _memberFormItemManager;

        public MemberFormItemSettingAppService(
            MemberFormItemManager memberFormItemManager
            )
        {
            _memberFormItemManager = memberFormItemManager;
        }

        public async Task<MemberFormItemDto> Add(AddMemberFormItemDto input)
        {
            var item = new MemberFormItem
            {
                Name = input.Name,
                DisplayName = input.DisplayName,
                Type = input.Type,
                Tag = input.Tag
            };
            await _memberFormItemManager.Add(item);
            return ObjectMapper.Map<MemberFormItemDto>(item);
        }

        public async Task<MemberFormItemDto> Update(UpdateMemberFormItemDto input)
        {
            var item = await _memberFormItemManager.Get(input.Id);
            item.DisplayName = input.DisplayName;
            item.Type = input.Type;
            item.Tag = input.Tag;
            await _memberFormItemManager.Update(item);
            return ObjectMapper.Map<MemberFormItemDto>(item);
        }

        public async Task Delete(EntityDto input)
        {
            await _memberFormItemManager.Delete(input.Id);
        }

        public async Task<List<MemberFormItemDto>> GetAll()
        {
            var items = await _memberFormItemManager.GetAll();
            return ObjectMapper.Map<List<MemberFormItemDto>>(items);
        }

        public async Task SetEnabled(EntityDto input)
        {
            await _memberFormItemManager.Enabled(input.Id, true);
        }

        public async Task SetDisabled(EntityDto input)
        {
            await _memberFormItemManager.Enabled(input.Id, false);
        }

        public async Task SetEnabledWhenRegister(EntityDto input)
        {
            await _memberFormItemManager.EnableWhenRegister(input.Id, true);
        }

        public async Task SetDisabledWhenRegister(EntityDto input)
        {
            await _memberFormItemManager.EnableWhenRegister(input.Id, false);
        }

        public async Task SetIsRequired(EntityDto input)
        {
            await _memberFormItemManager.IsRequire(input.Id, true);
        }

        public async Task SetNotRequired(EntityDto input)
        {
            await _memberFormItemManager.IsRequire(input.Id, false);
        }
    }
}
